import http from "@/utils/http";
import {EnumAlias} from "@/utils/common";
import axios from "axios";

export function userInfo(params?: object) {
  return http({
    url: `/${EnumAlias.PROJECT}/${EnumAlias.MODULE_AUTH}/session/userInfo`,
    method: "get",
    params
  });
}

export function getLoginUser(params?: object) {
  return http({
    url: `/${EnumAlias.PROJECT}/${EnumAlias.MODULE_AUTH}/session/getLoginUser`,
    method: "get",
    params
  });
}

export function dictTypeList(params?: object) {
  return http({
    url: `/${EnumAlias.PROJECT}/${EnumAlias.MODULE_SYS}/dictType/tree`,
    method: "get",
    params
  });
}

export function dynamicFormApi(params?: object) {
  return http({
    url: `/${EnumAlias.PROJECT}/${EnumAlias.MODULE_SYS}/dictType/tree`,
    method: "get",
    params
  });
}
//获取审批流模板
export function userFlowDesignLis(params?: object) {
  return http({
    url: `/${EnumAlias.PROJECT}/${EnumAlias.MODULE_MALL}/businessTypeRFlowDesign/UserFlowDesignList`,
    method: "get",
    params
  });
}
//获取当前节点ID
export function flowFlowNode(params?: object) {
  return http({
    url: `${EnumAlias.PROJECT}/${EnumAlias.MODULE_MALL}/flow/flowNode`,
    method: "get",
    params
  });
}
//流传流程
export function getFlowNodes(params?: object) {
  return http({
    url: `${EnumAlias.PROJECT}/${EnumAlias.MODULE_WORKFLOW}/flowInstance/getFlowNodes`,
    method: "get",
    params
  });
}
//获取审批历史
export function queryHistories(params?: object) {
  return http({
    url: `${EnumAlias.PROJECT}/${EnumAlias.MODULE_WORKFLOW}/flowInstance/queryHistories`,
    method: "get",
    params
  });
}
//获取可退回的节点

export function getNewFlowOperationHistory(data?: object) {
  return http({
    url: `${EnumAlias.PROJECT}/${EnumAlias.MODULE_WORKFLOW}/flowInstance/getNewFlowOperationHistory`,
    method: "post",
    headers: {
      "Content-Type": "application/json"
    },
    data
  });
}
export function upload(
  data: object,
  count: number = 1,
  group: string = "default",
  platform: string = "pc"
) {
  let url = "";
  if (count > 1) {
    url = "uploadFiles";
  } else {
    url = "uploadFile";
  }
  return http({
    url: `/${EnumAlias.PROJECT}/${EnumAlias.MODULE_SYS}/materia/${url}?group=${group}&platform=${platform}`,
    method: "post",
    data
  });
}
//华为obs上传
//创建桶
export function huaWeiDoCreate(data?: object) {
  return http({
    url: `${EnumAlias.PROJECT}/${EnumAlias.MODULE_MALL}/huaWei/doCreate`,
    method: "post",
    data
  });
}
//删除对象
export function huaWeiDoDelete(data?: object) {
  return http({
    url: `${EnumAlias.PROJECT}/${EnumAlias.MODULE_MALL}/huaWei/doDelete`,
    method: "post",
    data
  });
}
//设置/获取对象acl
export function huaWeiDoObjectAcl(data?: object) {
  return http({
    url: `${EnumAlias.PROJECT}/${EnumAlias.MODULE_MALL}/huaWei/doObjectAcl`,
    method: "post",
    data
  });
}
//获取对象
export function huaWeiDoGetObject(data?: object) {
  return http({
    url: `${EnumAlias.PROJECT}/${EnumAlias.MODULE_MALL}/huaWei/doGetObject`,
    method: "post",
    data
  });
}
//上传对象
export function huaWeiDoCreateObject(params?: object) {
  return http({
    url: `${EnumAlias.PROJECT}/${EnumAlias.MODULE_MALL}/huaWei/doCreateObject`,
    method: "get",
    params
  });
}
//设置/获取/删除桶 cors
export function huaWeiDoBucketCors(data?: object) {
  return http({
    url: `${EnumAlias.PROJECT}/${EnumAlias.MODULE_MALL}/huaWei/doBucketCors`,
    method: "post",
    data
  });
}
export function obsUploadApi(data?: any, obsUrl?: string, headers?: any) {
  let request: any = {
    method: "PUT",
    url: obsUrl,
    withCredentials: false,
    headers: {
      "Content-Type": headers["content-Type"]
    },
    validateStatus: function (status) {
      return status >= 200;
    },
    maxRedirects: 0,
    responseType: "json",
    data: data
  };

  return axios.request(request).then(function (response) {
    if (response.status < 300) {
    }
  });
}
